home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / ezhint.exe / READ.ME < prev    next >
Text File  |  1992-12-09  |  3KB  |  75 lines

  1.     This file demonstrates a simple method of implementing the 'hint'
  2. functionality of Turbo Vision status lines. Hints are text that appears to
  3. the right on the status line, and is seperated from the status line items
  4. by a vertical line. Hints are somewhat like 'quick and dirty help' messages;
  5. the hint that appears is determined by the focused item's help context.
  6.  
  7.     In general, implementing hints is easy - you just derive a new class
  8. from TStatusLine, and override the hint() method. The new hint() method is
  9. passed a ushort that is a help context; it needs to return a const char * to
  10. an asciiz string that represents the 'hint' for that context.
  11.  
  12.     Since help contexts need to start at 1000 (TV reserves 0..999), and
  13. because of the nature of collections, its difficult to instantiate a string
  14. collection to correspond to these help contexts. To the rescue is my Strings
  15. class uploaded to the BCPPDOS forum (TV section) on CIS. Though the initial
  16. reason I wrote this class was for a completely different reason (easy use
  17. of String Resource files), it works very well as a source of the string
  18. information for status line hints.
  19.  
  20.     The way it ties together is this: First, you need to derive the new
  21. TStatusLine class that overrides the hint() method. In EZHINT.CPP, this new
  22. class is called THintStatusLine. This class has a Strings member, which is
  23. initialized in the THintStatusLine ctor. There are 2 ways to initialize a
  24. Strings object: call load() with char * - this initializes the object from a
  25. String Resource file; alternatively, you can call load() with a statically
  26. allocate an array of StrRef items (see STRINGS.H) - this is the method
  27. demonstrated in EZHINT.CPP.
  28.  
  29.     class THintStatusLine : public TStatusLine
  30.         {
  31.         public:
  32.  
  33.             THintStatusLine( const TRect& bounds, TStatusDef& aDefs );
  34.  
  35.             virtual const char *hint( ushort aHelpCtx );
  36.  
  37.         protected:
  38.  
  39.             Strings s;
  40.         };
  41.  
  42.     StrRef strRef[] = {
  43.         { hcCtx1, "help 1" },
  44.         { hcCtx2, "help 2" },
  45.         { hcCtx3, "help 3" },
  46.         { srNull, 0        }
  47.         };
  48.  
  49.     THintStatusLine::THintStatusLine( const TRect& bounds,
  50.             TStatusDef& aDefs ) :
  51.             TStatusLine(bounds, aDefs)
  52.         {
  53.         s.load(strRef);
  54.         }
  55.  
  56.     Next, you must declare what the new hint() method does: this is very
  57. simple because it either returns s[helpCtx] (s is the Strings member) if this
  58. is a non-null value, or "" (ie helpCtx was not in s). Note that you can't
  59. just return a null pointer - TStatusLine::draw() freaks on this and prints
  60. spurious characters:
  61.  
  62.     const char *THintStatusLine::hint( ushort aHelpCtx )
  63.         {
  64.         char *p = s[aHelpCtx];
  65.         if( p == 0 )
  66.             return "";
  67.         else
  68.             return p;
  69.         }
  70.  
  71.     That's really all there is to it!
  72.  
  73.     Pat Reilly (TeamB)
  74.     70274,161
  75.